package com.seu.me.thread.day3.coll013;

import java.util.concurrent.LinkedBlockingDeque;

/**
 * Created by feihu.Mr on 2017/11/19.
 */
public class UseDeque {

    public static void main(String[] args) {

        LinkedBlockingDeque<String> dq = new LinkedBlockingDeque<String>(11);
        dq.addFirst("a");
        dq.addFirst("b");
        dq.addFirst("c");
        dq.addFirst("d");
        dq.addFirst("e");
        dq.addLast("f");
        dq.addLast("g");
        dq.addLast("h");
        dq.addLast("i");
        //队列已满，添加失败，报错
        dq.addLast("j");

        // 添加元素不会报错
        dq.offerFirst("k");
        dq.offerLast("m");

        System.out.println("查看头元素：" + dq.peekFirst());
        System.out.println("获取尾元素：" + dq.pollLast());
        Object[] objs = dq.toArray();

        for (int i = 0; i < objs.length; i++) {
            System.out.println(objs[i]);
        }

    }
}
